# waa.py
# windows application automation - HU data 2 Maros 

import glob
import win32api
import win32com.client

# sleep (seconds)
sleep = lambda x: win32api.Sleep(x*1000)

# setup custom mapping of oo
#REM oo/View/Toolbars/Customize/Keyboard .... F11 = replaceHex0A
#REM oo/View/Toolbars/Customize/Keyboard .... F3 = hu_files_0228
#REM oo/View/Toolbars/Customize/Keyboard .... Shift+F3 = (Application)Exit

for f in glob.glob('*.dat'):

    print f
    shell = win32com.client.Dispatch("WScript.Shell")
    shell.Run("notepad %s"%f)
    sleep(2)
    #shell.AppActivate("Calc")

    """
    # macro :: replaceHex0A
    shell.SendKeys("{F11}")
    sleep(6)
    # confirm :: "Nothing found" dialogs
    shell.SendKeys("{ENTER}")
    sleep(1)
  
    # run macro :: hu_files_0228
    shell.SendKeys("{F3}")
    """
    for i in range(3):
        shell.SendKeys("{ENTER}{TAB}A{TAB}B{TAB}C{ENTER}")
        #sleep(1)
    
    # close scalc
    shell.SendKeys("aaa")
    sleep(1)
    #shell.SendKeys("^S")
    for i in (1,2,3,4,5,6,7,8,9):
        sleep(1)
        shell.SendKeys("{ENTER}")
    shell.SendKeys("Now we shall Save the file ...{ENTER}")
    sleep(2)
    shell.SendKeys("%FS")
    # blast the current window with ALT F4 ..
    shell.SendKeys("%{F4}")
